<template>
  <div id="app">
    <!-- 标签名一般用小写nav-bar与navBar等价 -->
   <transition :name="transitionName">
      <router-view ></router-view>
   </transition>
    <nav-bar></nav-bar>
  </div>
</template>
<script>
  import navBar from '@/components/NavBar'
  export default {
    data(){
      return {
        transitionName:'slide-left'
      }
    },
    components: {
      navBar
    },
  watch:{
    $route(to,from){
        if(to.meta.index > from.meta.index){
            this.transitionName = 'slide-left';//向左划
        }
        else if(to.meta.index < from.meta.index){
            this.transitionName = 'slide-right';//向右划
        }
        else {
            this.transitionName = '';//同级无过渡效果
        }
    }
  }
  }
</script>

<style lang="less">
html, body {
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
}
#app {
  height: 100%;
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  // 作用？？？
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.router-view {
  width: 100%;
  height: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}

.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active{
    height: 100%;
    will-change: transform;
    transition: all 500ms;
    position: absolute;
    backface-visibility: hidden;
}
.slide-right-enter{
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active{
    opacity: 0;
    transform: translate3d(100%, 0, 0);
}
.slide-left-enter{
    opacity: 0;
    transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active{
    opacity: 0;
    transform: translate3d(-100%, 0, 0);
}

.van-badge--fixed {
  z-index: 1000;
}
</style>